package org.speed.ddd;

import java.util.ArrayList;
import java.util.List;

public class EventPublisher {
	
	private static EventPublisher INSTANCE = new EventPublisher();
	
	private List<Domain> listeners = new ArrayList<>();

	public static EventPublisher getInstance() {
		return INSTANCE;
	}
	
	void subscri(Domain domain) {
		listeners.add(domain);
	}
	
	public void notifyEvent(DomainEvent event) {
		
		listeners.forEach(domain -> {
			Domain clazz = event.getTarget();
			if(domain.getClass() == clazz.getClass() ) {
				domain.onAction(event);
				return;
			}
		});
		
	}
	
	public void notifyEventUseAsync(DomainEvent event) {
		
	}
	
}
